home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
LANG
/
C
/
GCC
/
V2-4-5
/
GCCEXTSR
/
Virtual
/
!Virtual
/
c
/
poll
< prev
Wrap
Text File
|
1993-09-07
|
5KB
|
195 lines
/*
* poll.c
* Part of the !Virtual distribution
* (c) bdb/nas/fo, 1992-3
*/
#include "swis.h"
#include "swiv.h"
#include "wimp.h"
#include "virtual.h"
#include "lib.h"
#include "pager.h"
#include "output.h"
#include "asm.h"
#include "poll.h"
void Poll(WKSP *w)
{ int reason;
int suspended=0;
int tm;
wimp_eventdata b;
char tbuf[256];
if (!worksemaphore)
printf("Ooops!");
printflush(w);
usermode();
for (;;)
{
swi(OS_Release,IN(R0|R1|R2),3,&NormWriteC,w);
if (w->nice_delay > 0)
{
swi(OS_ReadMonotonicTime,OUT(R0),&tm);
swi(Wimp_PollIdle,IN(R0|R1|R2)|OUT(R0),suspended,&b,tm+(w->nice_delay),&reason);
} else swi(Wimp_Poll,IN(R0|R1)|OUT(R0),suspended,&b,&reason);
swi(OS_Claim,IN(R0|R1|R2),3,&NormWriteC,w);
switch (reason)
{ case wimp_ENULL:
break;
case wimp_ESEND:
case wimp_ESENDWANTACK:
switch (b.msg.hdr.action)
{
case wimp_MCLOSEDOWN:
svcmode();
RealDoOff(w);
break;
case wimp_MSETSLOT:
/* if (b.msg.data.words[1]!=w->ourtask)
break; */
if (b.msg.data.words[0]>0) /* min 2 pages */
{ svcmode();
SetRealMem(w, b.msg.data.words[0]);
usermode();
}
b.msg.hdr.your_ref=b.msg.hdr.my_ref;
swi(Wimp_SendMessage,IN(R0|R1|R2),wimp_EACK,&b,b.msg.hdr.task);
break;
case /* TaskWindow_Input */ 0x808c0:
{ char *p=(char *)&b.msg.data.words[1];
int c;
for (c=b.msg.data.words[0];c>0;c--,p++)
{ if (*p==w->EscapeChar && !w->EscapeCharEnable)
w->EscapeCondition = 1;
else
{ if (w->incount<INSIZE)
w->inbuf[(w->instart+w->incount++)%INSIZE]=*p;
}
}
}
break;
case wimp_MDATASAVE:
/* This code (along with wimp_MRAMTRANSMIT) is for the reception of datasave messages
* from !edit,!srcedit,etc when they do 'Task input'. They should really use TaskWindow
* _Input messages, but don't, and they also ignore the size of buffer returned to them -
* always transferring upto 256 bytes in a chunk. Hence we receive to a temporary 256
* byte buffer (tbuf), and make a simple attempt to transfer this into the character input
* buffer (w->inbuf). If multiple 256-byte blocks are to be transferred, we ignore them.
* NAS - 07/09/93
*/
#ifdef DEBUG
printf("RamFetch:space %d\n", sizeof(tbuf));
printflush(w);
#endif
b.msg.data.ramfetch.addr = (char *) &tbuf;
b.msg.data.ramfetch.nbytes = sizeof(tbuf);
b.msg.hdr.your_ref = b.msg.hdr.my_ref;
b.msg.hdr.action = wimp_MRAMFETCH;
b.msg.hdr.size = sizeof(b.msg.data.ramfetch)+sizeof(b.msg.hdr);
swi(Wimp_SendMessage,IN(R0|R1|R2),wimp_ESENDWANTACK,&b,b.msg.hdr.task);
#ifdef DEBUG
printf("RamFetch: sent message\n");
printflush(w);
#endif
break;
case wimp_MRAMTRANSMIT:
{
char *p=(char *)&tbuf;
int c;
#ifdef DEBUG
printf("RamTransmit:%d\n",b.msg.data.ramtransmit.nbyteswritten);
printflush(w);
#endif
for (c=b.msg.data.ramtransmit.nbyteswritten;c>0;c--,p++)
{ if (*p==w->EscapeChar && !w->EscapeCharEnable)
w->EscapeCondition = 1;
else
{ if (w->incount<INSIZE)
w->inbuf[(w->instart+w->incount++)%INSIZE]=*p;
}
}
}
break;
case /* TaskWindow_Suspend */ 0x808c6:
#ifdef DEBUG
{ int i;
printf("Suspended: PC=%x ",w->regs[15]);
for (i=0;i<=14;i++)
printf("R%d=%x ",i,w->regs[i]);
printf("\n");
printf("MemoryLimit=%x, ApplicationSpace=%x, CurrentlyActiveObject=%x\n",
w->MemoryLimit, w->ApplicationSpace, w->CurrentlyActiveObject );
}
#else
printf("Suspended\n");
#endif
printflush(w);
suspended=1;
break;
case /* TaskWindow_Resume */ 0x808c7:
printf("Resumed\n");printflush(w);
suspended=0;
break;
case /* TaskWindow_Morite */ 0x808c4:
svcmode();
RealDoOff(w);
break;
default:
break;
}
continue;
default:
continue;
}
break;
}
svcmode();
FindPages(w); /* in case its changed */
worksemaphore=1;
}
int getc(WKSP *w)
{
int c;
if (!w->incount && !w->EscapeCondition)
{ Normal(w);
while (!w->incount && !w->EscapeCondition)
Poll(w);
Virtual(w);
}
if (w->EscapeCondition)
return -1;
c=w->inbuf[w->instart];
if (w->incount > 0) w->incount--;
if (++w->instart>=INSIZE)
{
w->instart=0;
w->incount=0;
}
return c;
}
/* Instant return getc - lower level than getc() */
int lowgetc(WKSP *w)
{
int c;
if (!w->incount) return -1;
if (w->EscapeCondition)
return -1;
c=w->inbuf[w->instart];
if (w->incount > 0) w->incount--;
if (++w->instart>=INSIZE)
{
w->instart=0;
w->incount=0;
}
return c;
}